/**
 * Created by bethinner on 5/24/16.
 */
import React, { Component } from 'react';

import { connect } from 'react-redux'
import Link from 'react-router/lib/Link'
import browserHistory from 'react-router/lib/browserHistory'


export default class MessageAlert extends Component {
    constructor(props) {
        super(props);

    }

    componentDidMount() {
        setTimeout(this.props.handle(this.props.type),2000);
    }

    shouldComponentUpdate(nextProps, nextState) {
        //setTimeout(this.props.handle(this.props.type),2000);
        setTimeout(this.props.handle(nextProps.type),2000);
        //console.log(nextProps);
        //console.log(nextState);
        return true;
    }

    getType(){
        if (this.props.type == 0) {
            return "success"
        }else{

            return "error"
        }
    }

    getImg(){
        if (this.props.type == -1) {
            return ""
        }
        else if (this.props.type == 0) {
          return(<img src="/public/img/success_msg_icon.png" />)
        }else{
            return(<img src="/public/img/wrong_msg_icon.png" />)
        }
    }

    render() {
        var Stype=this.getType();
        return (
            <div style={{width:"100%"}}>
                <div style={DivStyle}>
                    {this.getImg()}
                    <div>{this.props.message}</div>
                </div>
            </div>

        )
    }
}

let DivStyle = {
    //;width:500px;height:200px;left:50%;top:;margin-left:-250px;margin-top:-100px;border:solid 3px #ccc;z-index:99;
    backgroundColor:"white",
    fontSize: "18px",
    textAlign: "center",
    width: "52%",
    paddingTop:"10px",
    lineHeight: "44px",
    position: "fixed",
    top: "35%",
    left: "24%",
    zIndex: "999999",
    border:"1px solid #EEEEEE"
};
MessageAlert.defaultProps = {

    }

MessageAlert.propTypes = {
    message: React.PropTypes.string,
    type: React.PropTypes.string,
    handle: React.PropTypes.func,
}


